package Work03;

public class TicktThread {
    public static class Tickets {
        private int number;

        public Tickets(Work01.Tickets ti) {
        }

        public Tickets(int number) {
            this.number = number;
        }

        public void  ticket(int number) throws InterruptedException {//卖票
            //卖票的人
            String name = Thread.currentThread().getName();
            //判断剩下的票够不够
            synchronized (this) {
                if (this.number >= number) {
                    System.out.println(name + "卖票" + number + "张");
                    this.number -= number;
                    System.out.println("票还剩" + this.number + "张");
                }
                if (this.number == 0) {
                    System.out.println("票已售罄");
                }
            }
        }
        public int getNumber() {
            return number;
        }

        public void setNumber(int number) {
            this.number = number;
        }
    }

}
